import { doPost } from "../network/request";
import { saveToken } from "../utils/token_util";
import qs from "qs";

export async function login({ username, password }) {
    const ret = await doPost(
        "/user/login",
        qs.stringify({ username, password }),
        {
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
        }
    );

    const {
        data: { token },
    } = ret;
    token && saveToken(token);
    localStorage.setItem("username",username)

    return ret;
}
